<!--
 * @author: Spring
 * @create: 2021-06-17 09:27 AM
 * @license: MIT
 * @lastAuthor: Spring
 * @lastEditTime: 2021-06-17 11:21 AM
 * @desc: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .container {
      width: 600px;
      display: flex;
      justify-content: space-around;
      align-items: center;
    }

    .box {
      width: 200px;
      height: 295px;
      display: flex;
      flex-direction: column;
      border: 1px solid #EBEEF5;
      border-radius: 10px;
      display: flex;
      flex-direction: column;

    }

    .list {
      width: 100%;
      height: 40px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: #F5F7FA;
    }

    .title {
      width: 100%;
      height: 40px;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      background-color: #F5F7FA;
      padding: 0 5px;
    }

    .title>input{
      cursor: pointer;
    }

    .title>label{
      cursor: pointer;
      font-size: 16px;
      color: #303133;
    }

    .li {
      overflow: auto;
      display: flex;
      flex-direction: column;
      padding: 0 5px;
    }

    .arrows {
      width: 60px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      font-size: 18px;
      border-radius: 5px;
      background-color: #A0CFFF;
      color: #fff;
      cursor: pointer;
    }

    .lis {
      flex-shrink: 0;
      height: 35px;
      display: flex;
      align-items: center;
    }

    input {
      margin-right: 5px;
    }

    .label:hover{
      color: #409EFF !important; 
    }

    .number{
      color: #909399;
      font-size: 14px;
    }
  </style>
</head>

<body>
  <div id="app" class="container">
    <div class="left box">
      <div class="list listbox">
        <div class="title">
          <input @input="list1($event)" :disabled="ld" type="checkbox" v-model="listone" id="listt1">
          <label for="listt1">列表1</label>
        </div>
        <div class="number">{{leftM.length}}/{{left.length}}</div>
      </div>
      <div class="li">
        <div class="lis" v-for="(item,index) in left" :key="item">
          <input @change="canchoose" :disabled="item%4==0?true:false" type="checkbox" :id="item" :value="item"
          :style="{cursor:item%4!=0?'pointer':'default'}"
            v-model="leftM">
          <label :for="item" :style="{color:item%4==0?'#D2C9CC':'#606266',cursor:item%4!=0?'pointer':'default',fontSize:'14px'}"
          :class="item%4!=0?'label':''">备选项{{item}}</label>
        </div>
      </div>
    </div>
    <div class="arrows" @click="leftclick">
      < </div>
        <div class="arrows" @click="rightclick"> > </div>
        <div class="right box">
          <div class="list listbox">
            <div class="title">
              <input @input="list2($event)" :disabled="rd" v-model="listtwo" type="checkbox" id="listt2">
              <label for="listt2">列表2</label>
            </div>
            <div class="number">{{rightM.length}}/{{right.length}}</div>
          </div>
          <div class="li">
            <div class="lis" v-for="(item,index) in right" :key="item">
              <input @change="canchoose" :disabled="item%4==0?true:false" type="checkbox" :id="item" :value="item"
              :style="{cursor:item%4!=0?'pointer':'default'}"
                v-model="rightM">
              <label :for="item" :style="{color:item%4==0?'#D2C9CC':'#606266',cursor:item%4!=0?'pointer':'default',fontSize:'14px'}"
                :class="item%4!=0?'label':''" >备选项{{item}}</label>
            </div>
          </div>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script>
      var app = new Vue({
        el: '#app',
        data: {
          left: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
          leftM: [],
          right: [11, 12, 13, 14, 15],
          rightM: [],
          ld: false,
          rd: false,
          listone: false,
          listtwo: false
        },
        methods: {
          leftclick() {
            this.left = [...this.left, ...this.rightM]
            this.rightM.forEach(item => {
              this.right = this.right.filter(it => {
                return it != item
              })
            })
            this.left.sort((a, b) => {
              return a - b
            })
            this.rightM = []
            this.canchoose()
          },
          rightclick() {
            this.right = [...this.right, ...this.leftM]
            this.leftM.forEach(item => {
              this.left = this.left.filter(it => {
                return it != item
              })
            });
            this.right.sort((a, b) => {
              return a - b
            })
            this.leftM = []
            this.canchoose()
          },
          list1(e) {
            if (e.target.checked == true) {
              this.left.forEach(item => {
                if (item % 4 != 0) {
                  this.leftM.push(item)
                }
              })
            } else {
              this.leftM = []
            }
          },
          list2(e) {
            if (e.target.checked == true) {
              this.right.forEach(item => {
                if (item % 4 != 0) {
                  this.rightM.push(item)
                }
              })
            } else {
              this.rightM = []
            }
          },
          canchoose() {
            //判断全选是否可选
            if (this.left.length == 2) {
              this.ld = true
            } else {
              this.ld = false
            }
            if (this.right.length == 1) {
              this.rd = true
            } else {
              this.rd = false
            }
            //判断全选是否勾选
            if (this.left.length - 2 == this.leftM.length) {
              this.listone = true
            } else {
              this.listone = false
            }
            if (this.right.length - 1 == this.rightM.length) {
              this.listtwo = true
            } else {
              this.listtwo = false
            }
          }
        },
        mounted() {
        },
      })
    </script>
</body>

</html>